package com.fzj.example.design.composite;

import java.util.ArrayList;

/**
* @Description
* @Author  fanzj
* @Date   2020/5/10 4:32 下午
* @Param  
* @Return      
* @Exception   
* 
*/
public class Composite implements Component {

    private ArrayList<Component> children=new ArrayList<Component>();

    @Override
    public void add(Component c) {
        children.add(c);
    }

    @Override
    public void remove(Component c) {
        children.remove(c);
    }

    @Override
    public Component getChild(int i) {
        return children.get(i);
    }

    @Override
    public void operation() {
        for (Component obj :
                children) {
            obj.operation();
        }
    }
}
